#include <iostream>
#include <string>
#include <unordered_map>

#include <yaml-cpp/yaml.h>

#include "../include/graph.hpp"
  
int main()
{
  YAML::Node data_file;
  try
  {
    data_file = YAML::LoadFile("../data/Data.yaml");
  }
  catch(const std::exception& e)
  {
      std::cerr << e.what() << '\n';
  }
  int vertex_num = data_file["Graph"]["vertex_num"].as<int>();
  std::vector<std::vector<std::string>> edges = data_file["Graph"]["edges"].as<std::vector<std::vector<std::string>>>();
  std::vector<std::string> vertices = data_file["Graph"]["vertices"].as<std::vector<std::string>>();

  my_data::Graph graph(vertex_num+1);
  //设置顶点的名字
  graph.setNames(vertices);

  // 构造key:地名,value:编号映射map
  std::unordered_map<std::string,int> fmap;
  for(int i=1; i<=vertices.size(); ++i)
  {
    fmap.insert(std::pair<std::string,int>(vertices[i-1],i));
  }
  for(auto edge : edges)
  {
    // 插入边
    // edge[0]是第一个城市的编号, edge[1]是第二个城市的编号
    graph.addEdge(fmap[edge[0]], fmap[edge[1]]);
  }
  std::cout<<"深度优先遍历："<<std::endl;
  auto tree_set = graph.DFS(1);
  std::cout<<"\n----------------------------------------------------------------"<<std::endl;
  std::cout<<"广度优先遍历:"<<std::endl;
  graph.BFS(1);
  std::cout<<"\n";
  

  return 0;
}